﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_EditMovieByID : System.Web.UI.Page
{
    DataClassesDataContext dtc = new DataClassesDataContext();
    
    Product pd = new Product();
    protected void Page_Load(object sender, EventArgs e)
    {
        if(this.IsPostBack==false)
        {
        tblMovie mv = pd.GetMovieById2(Session["MVID"].ToString());
        txtMovieID.Text = mv.MovieID;
        txtMovieName.Text = mv.MovieName;
        txtFilmDirector.Text = mv.FilmDirector;
        txtActors.Text = mv.Actors;
        txtAboutMovie.Text = mv.AboutUsFile;
        txtCa.Text = mv.Category;
        DateTime end = new DateTime();
        end =DateTime.Parse( mv.CloseDay.ToString()).Date;
        txtCloseDay.Text = end.Month+"/"+end.Day+"/"+end.Year;
        txtCountry.Text = mv.country;
        txtNotes.Text = mv.Notes;
        DateTime start = new DateTime();
        start = DateTime.Parse(mv.ReleasedDay.ToString()).Date;
        txtReleasedDate.Text = start.Month + "/" + start.Day + "/" + start.Year;
        }

    }
    protected void btnSummit_Click(object sender, EventArgs e)
    {
        int cl=0;
        if (UploadImage.HasFile)
        {
            cl=1;
        }
        try
        {

            if(pd.UpdateMovie(Session["MVID"].ToString(), txtMovieName.Text, txtFilmDirector.Text, txtActors.Text, txtCa.Text, txtCountry.Text, upload(), txtAboutMovie.Text, DateTime.Parse(txtReleasedDate.Text.Trim()), DateTime.Parse(txtCloseDay.Text.Trim()), int.Parse(ddlStatus.SelectedValue), txtNotes.Text,cl))
            {
            Response.Redirect("EditMovie.aspx");
                }
        }
        catch (Exception ex)
        {
            lblError.Visible = true;
            lblError.Text = "No" + ex.ToString();
        }
    }
    string upload()
    {

        if (UploadImage.HasFile)
        {
            Random rb = new Random();
            int rand = rb.Next(1000);
            string name = rand.ToString() + "_" + UploadImage.PostedFile.FileName;
            try
            {
                UploadImage.SaveAs(Server.MapPath("~/images/Movie/" + name));
                return name;
            }
            catch (Exception ex)
            {
                return ex.ToString();
            }
        }
        else
        {
            return "no-picture.jpg";
        }

    }
}